<template>
  <div>
    <h1>Login</h1>
    <br>
    <h1>登录中{{time}}...</h1>
  </div>
</template>

<script>
export default {
  data() {
    return {
      time: 3,
    };
  },
  created() {
    this.countDown();
  },
  methods: {
    countDown() {
      if (this.time > 0) {
        setTimeout(() => {
          this.time -= 1;
          this.countDown();
        }, 1000);
      } else {
        this.time = 'ok';
        alert('login success');
        sessionStorage.setItem('userName', 'admin');
        console.log(this.$route);
        if (this.$route.query.redirect) {
          // 登录后禁止返回登录页
          this.$router.replace({ path: this.$route.query.redirect });
        } else {
          this.$router.replace({ path: '/' });
        }
      }
    },
  },
};
</script>

<style lang="scss">
</style>